package com.oyjd.framework.ui.corner;

import java.util.List;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.oyjd.R;

public class CornerView extends LinearLayout {
	private LayoutInflater flater;// 布局加载器
	private LinearLayout cornerListView;// 容器
	private LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	private LayoutParams lp2 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

	/**
	 * 构造函数
	 * 
	 * @param context
	 */
	public CornerView(Context context) {
		super(context);
		init();
	}

	/**
	 * 构造函数
	 * 
	 * @param context
	 * @param attrs
	 */
	public CornerView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	/**
	 * 初始化
	 */
	private void init() {
		// 初始化布局加载器
		flater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		flater.inflate(R.layout.inner_corner_list, this, true);
		cornerListView = (LinearLayout) this.findViewById(R.id.cornerListView);
		lp2.setMargins(25, 15, 25, 15);
	}

	/**
	 * 设置数据
	 * 
	 * @param data
	 */
	public void setData(List<View> data) {
		cornerListView.removeAllViews();
		for (int i = 0; i < data.size(); i++) {
			if (i > 0) {
				TextView line = new TextView(getContext());
				line.setHeight(1);
				line.setBackgroundResource(R.color.corner_border);
				cornerListView.addView(line, lp);
			}
			cornerListView.addView(data.get(i), lp2);
		}
	}

}
